package com.settlement.system.parse.formula;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * 数字计算
 *
 * @author Ximi
 * @since 2020/10/10
 */
public class NumberCalculator extends AbstractOperatorCalculator<BigDecimal> {

    public NumberCalculator(PlaceHoldParse placeHoldParse) {
        super(placeHoldParse);
    }

    @Override
    public BigDecimal addition(BigDecimal a, BigDecimal b) {
        return a.add(b);
    }

    @Override
    public BigDecimal substract(BigDecimal a, BigDecimal b) {
        return a.subtract(b);
    }

    @Override
    public BigDecimal multiply(BigDecimal a, BigDecimal b) {
        return a.multiply(b);
    }

    @Override
    public BigDecimal devide(BigDecimal a, BigDecimal b) {
        return a.divide(b, 2, RoundingMode.HALF_UP);
    }

    @Override
    public BigDecimal conver(String arg) {
        return BigDecimal.valueOf(Double.valueOf(arg));
    }

}
